//package com.graph;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.iqiyi.cola.cache.ShotConstant;
//import com.iqiyi.cola.support.DebugLogEnum;
//import com.iqiyi.cola.utils.BeanUtil;
//import com.iqiyi.cola.utils.LoggerUtil;
//import java.nio.charset.StandardCharsets;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.Iterator;
//import java.util.List;
//import java.util.TreeMap;
//import java.util.TreeSet;
//import lombok.Data;
//
///**
// *code_repository_delta
// *@author huliangjun
// *@date 2018/12/2 23:42
// */
//
//public class GraphUtils {
//
//    /** key-地图id ,value-平台有向图*/
//    private static HashMap<Integer, MapGraph> graph = new HashMap<>(2);
//    /** key-地图id ,value-改地图的所有平台*/
//    private static HashMap<Integer, List<Platform>> platforms = new HashMap<>(10);
//    /** 日志*/
//    private static LoggerUtil logger = BeanUtil.getLogger();
//
//    /**
//     * 将地图数据转为有向图
//     * @author huliangjun
//     * @date 2018/12/2 23:24
//     * @param buff
//     * @param mapId
//     * @return void
//     */
//    public static void loadGraph(byte[] buff, Integer mapId) {
//        //单个地图json
//        String jumpJson = new String(buff, StandardCharsets.UTF_8);
//        JSONObject curtMapObj = JSON.parseObject(jumpJson);
//        JSONArray gridArray = curtMapObj.getJSONArray("graph");
//        MapGraph mapGraph = new MapGraph();
//        for (Iterator<Object> gridIterator = gridArray.iterator(); gridIterator.hasNext(); ) {
//            JSONObject curtGraphObj = (JSONObject) gridIterator.next();
//            Graph graph = JSONObject.parseObject(curtGraphObj.toJSONString(), Graph.class);
//            Edge edge = mapGraph.addEdge(graph.getFrom(),graph.getTo());
//            String[] jumps = graph.getJumpPoint().split("\\|");
//            for(int i = 0 ;i < jumps.length ; i++){
//                String[] items = jumps[i].split(ShotConstant.POINT_SEPERATOR);
//                edge.addJumpPoint(new JumpPoint(Double.parseDouble(items[0]),Double.parseDouble(items[1]),Integer.parseInt(items[2])));
//            }
//        }
//        graph.put(mapId,mapGraph);
//        //解析平台数据
//        JSONArray platformArray = curtMapObj.getJSONArray("platforms");
//        List<Platform> platformList = new ArrayList<>(platformArray.size());
//        for (Iterator<Object> gridIterator = platformArray.iterator(); gridIterator.hasNext(); ) {
//            JSONObject curtPlatformObj = (JSONObject) gridIterator.next();
//            Platform platform = JSONObject.parseObject(curtPlatformObj.toJSONString(), Platform.class);
//            if(platform != null && platform.getPixelPosXRange().contains(ShotConstant.POINT_SEPERATOR)){
//                String[] range = platform.getPixelPosXRange().split(ShotConstant.POINT_SEPERATOR);
//                platform.setStart(Double.parseDouble(range[0]));
//                platform.setEnd(Double.parseDouble(range[1]));
//            }
//            platformList.add(platform);
//
//        }
//        platforms.put(mapId,platformList);
//    }
//
//    /**
//     * 获取起点到终点可用最短路径
//     * @author huliangjun
//     * @date 2018/12/3 9:22
//     * @param mapId 指定地图id
//     * @param source 起点名称
//     * @param dest 终点名称
//     * @return java.util.TreeMap<java.lang.Integer,java.util.TreeSet<com.iqiyi.cola.robot.graph.JumpPoint>>
//     */
//    public static TreeMap<Integer, TreeSet<JumpPoint>> getUsablePath(Integer mapId, String source, String dest) {
//        TreeMap<Integer, TreeSet<JumpPoint>> path = null;
//        if (!graph.isEmpty()) {
//            MapGraph mapGraph = graph.get(mapId);
//            if (mapGraph == null) {
//                logger.debugFormat(DebugLogEnum.SHOT_AI_BEHAVIOR_TREE_INFO.code(), true, "枪术大战AI-寻找最短路径-地图的有向图数据未找到-mapId,source,dest", mapId,
//                    source, dest);
//                return null;
//            } else {
//                mapGraph.unweighted(source);
//                path = mapGraph.calculatorPath(dest);
//            }
//        }
//        return path;
//    }
//
//    @Data
//    private static class Platform {
//        private String name;
//        private String pixelPosY;
//        private String pixelPosXRange;
//        private Double start;
//        private Double end;
//    }
//
//    @Data
//    private static class Graph {
//        private String from;
//        private String to;
//        private String jumpPoint;
//    }
//}
